package com.example.automanagement.service.serviceImpl;

import com.example.automanagement.mapper.OrderMapper;
import com.example.automanagement.mapper.TimeLineMapper;
import com.example.automanagement.service.TimeLineService;
import com.example.automanagement.views.AutoOrderTimeLine;
import com.example.automanagement.views.RepairOrderTimeLine;
import com.example.automanagement.views.TimeLineNode;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class TimeLineServiceImpl implements TimeLineService {
    @Resource
    private TimeLineMapper timeLineMapper;

    // 作者于2024/01/18 19:52写下下面这堆答辩代码，在此标注，以警醒众人
    @Override
    public List<TimeLineNode> getTimeLineNodeList(int orderId,String orderType,int progress){
        List<String> contentList = new ArrayList<>();
        List<String> timeList = new ArrayList<>();
        if(orderType.equals("用车工单")){
            contentList.add("申请提交");
            contentList.add("部门审批");
            contentList.add("综合办审批");
            contentList.add("结束");
            AutoOrderTimeLine autoOrderTimeLine=timeLineMapper.getAutoOrderTimeLine(orderId);
            timeList.add(autoOrderTimeLine.getSubmitTime());
            timeList.add(autoOrderTimeLine.getDepartmentApprovalTime());
            timeList.add(autoOrderTimeLine.getGeneralApprovalTime());
            timeList.add("");
        }
        else if(orderType.equals("维修工单")) {
            contentList.add("申请提交");
            contentList.add("综合办审批");
            contentList.add("结束");
            RepairOrderTimeLine repairOrderTimeLine = timeLineMapper.getRepairOrderTimeLine(orderId);
            timeList.add(repairOrderTimeLine.getSubmitTime());
            timeList.add(repairOrderTimeLine.getGeneralApprovalTime());
            timeList.add("");
        }
        List<TimeLineNode> timeLineNodes=new ArrayList<>();
        for (int i = 0; i < contentList.size(); i++) {
            TimeLineNode timeLineNode = new TimeLineNode();
            timeLineNode.setContent(contentList.get(i));
            timeLineNode.setTimeStamp(timeList.get(i));
            if (i < progress) {
                timeLineNode.setType("success");
                timeLineNode.setIcon("el-icon-check");
            } else if (i == progress) {
                timeLineNode.setType("warning");
                timeLineNode.setIcon("el-icon-more");
            } else {
                timeLineNode.setType("");
                timeLineNode.setIcon("");
            }
            timeLineNodes.add(timeLineNode);
        }
        System.out.println(timeLineNodes);
        return timeLineNodes;
    };

}
